// Check if n is prime
pub fn is_prime(n: u64) -> bool {
    if n == 1 {
        return false;
    }

    if n == 2 {
        return true;
    }

    if n & 1 == 0 {
        return false;
    }

    let mut i = 3;
    let upbound = (n as f64).sqrt() as u64;
    while i <= upbound {
        if n % i == 0 {
            return false;
        }
        i += 2;
    }

    true
}

pub fn verify_odd_composite(n: u64) -> bool {
    if n % 2 == 0 || is_prime(n) {
        return true;
    }

    let mut k = 0;
    while k * k <= n / 2 {
        let p = n - 2 * k * k;
        if p > 0 && is_prime(p) {
            return true;
        }
        k += 1;
    }

    false
}

pub fn goldbach_conjecture() -> u64 {
    let mut first = 9;
    loop {
        if !verify_odd_composite(first) {
            break;
        }
        first += 2;
    }
    let mut second = first + 2;
    loop {
        if !verify_odd_composite(second) {
            break;
        }
        second += 2;
    }
    first + second
}
